/**
 * Copyright (C) 2025 ROKAE (Beijing) Technology Co., LTD.
 * All Rights Reserved.
 *
 * Information in this file is the intellectual property of Rokae Technology Co., Ltd,
 * And may contains trade secrets that must be stored and viewed confidentially.
 *
 * @file InspireRobotsPlugin.cpp
 * @brief 初始化 UI 界面，并注册 RL 指令
 */
#include "InspireRobotsPlugin.h"

XPLUGIN_REGISTER(PLUGIN_NAME, InspireRobotsPlugin)

xplugin::InspireRobotsPlugin::InspireRobotsPlugin(QObject *parent)
    :xplugin::PluginBase(parent)
{}

void xplugin::InspireRobotsPlugin::init()
{
    m_widget = new InspireRobotsWidget;
    xplugin::CreateCenterWidget(PLUGIN_NAME, m_widget);
}

void xplugin::InspireRobotsPlugin::afterInit()
{
    // 创建 RLManager，用于注册流程控制脚本中可用的 RL 指令
    m_rlManager = new xplugin::RLManager(this);

    // ----- 注册 InspireRobotsSetAngle 指令 -----
    m_rlManager->createTypeKey("InspireRobotsSetAngle");
    m_rlManager->createSkeleton("InspireRobotsSetAngle", "InspireRobotsSetAngle");
    m_rlManager->createInsDescribe("InspireRobotsSetAngle", QString(tr("Set Angle")));    // 描述
    m_rlManager->createPattern("InspireRobotsSetAngle", QString("^\\s*%1\\s*(?://.*)?$").arg("InspireRobotsSetAngle")); // 匹配正则
    m_rlManager->createInsertWidget("InspireRobotsSetAngle", [](){
        return new xplugin::RLSetAngleWidget("InspireRobotsSetAngle"); // 插入时使用的控件
    });

    // ----- 注册 InspireRobotsSetForce 指令 -----
    m_rlManager->createTypeKey("InspireRobotsSetForce");
    m_rlManager->createSkeleton("InspireRobotsSetForce", "InspireRobotsSetForce");
    m_rlManager->createInsDescribe("InspireRobotsSetForce", QString(tr("Set Force")));    // 描述
    m_rlManager->createPattern("InspireRobotsSetForce", QString("^\\s*%1\\s*(?://.*)?$").arg("InspireRobotsSetForce")); // 匹配正则
    m_rlManager->createInsertWidget("InspireRobotsSetForce", [](){
        return new xplugin::RLSetForceWidget("InspireRobotsSetForce"); // 插入时使用的控件
    });

    // ----- 注册 InspireRobotsSetSpeed 指令 -----
    m_rlManager->createTypeKey("InspireRobotsSetSpeed");
    m_rlManager->createSkeleton("InspireRobotsSetSpeed", "InspireRobotsSetSpeed");
    m_rlManager->createInsDescribe("InspireRobotsSetSpeed", QString(tr("Set Speed")));    // 描述
    m_rlManager->createPattern("InspireRobotsSetSpeed", QString("^\\s*%1\\s*(?://.*)?$").arg("InspireRobotsSetSpeed")); // 匹配正则
    m_rlManager->createInsertWidget("InspireRobotsSetSpeed", [](){
        return new xplugin::RLSetSpeedWidget("InspireRobotsSetSpeed"); // 插入时使用的控件
    });

    // ----- 注册 InspireRobotsGetAngle 指令 -----
    m_rlManager->createTypeKey("InspireRobotsGetAngle");
    m_rlManager->createSkeleton("InspireRobotsGetAngle", "InspireRobotsGetAngle");
    m_rlManager->createInsDescribe("InspireRobotsGetAngle", QString(tr("Get Angle")));    // 描述
    m_rlManager->createPattern("InspireRobotsGetAngle", QString("^\\s*%1\\s*(?://.*)?$").arg("InspireRobotsGetAngle")); // 匹配正则
    m_rlManager->createInsertWidget("InspireRobotsGetAngle", [](){
        return new xplugin::RLGetAngleWidget("InspireRobotsGetAngle"); // 插入时使用的控件
    });

    // 指令分组
    m_rlManager->createTypeToGroup("InspireRobotsPlugin",
                                   QStringList() << "InspireRobotsSetAngle" << "InspireRobotsSetForce"
                                                 << "InspireRobotsSetSpeed" << "InspireRobotsGetAngle");

    // 创建分组界面标题
    m_rlManager->createGroups(tr("InspireRobots Group"), "InspireRobotsPlugin");
}


